require "Common/define"
require "Logic/Config"
require "Common/functions"

FuncSlotItem = {};
HelperFunc.SetUIEnv(FuncSlotItem)
local this = FuncSlotItem;

this.gameObject = nil;
this.transform = nil;
this.LuaBehaviour = nil;
this.img_Icon = nil;
this.txt_Name = nil;


function FuncSlotItem.Init()
    local name, packageName = getUIName(PanelNames.FuncSlotItem);
    panelMgr:ShowUI(name, packageName, this.onCreate,Config.useLocalUI);
end

function FuncSlotItem.onCreate(obj)
    obj.visible = false;
end

function FuncSlotItem.initData(obj,data)
    -- gameObject = obj;
    -- transform = obj.transform;
    img_Icon = obj:GetChild("icon")-- :GetComponent("Image");
    txt_Name = obj:GetChild("title")-- :GetComponent("TextMeshProUGUI");

    if data ~= nil then
        if data["icon"] ~= nil then
            -- resMgr:LoadIconFromPrefab("FuncAtlas", data["icon"],function(sp)
            --     img_Icon.gameObject:SetActive(true);
            --     img_Icon.sprite = sp;
            -- end);
            img_Icon.url = "ui://FuncAtlas/"..data["icon"];
        end
        if data["name"] ~= nil then
            txt_Name.text = data["name"];
        end
    end
end

return FuncSlotItem;